var axios = require('axios');
var Web3 = require("web3");
var fs = require('fs');
var os = require('os');
var config = require('./config/config.js')
var web3 = new Web3(new Web3.providers.HttpProvider(config.HttpProvider));


async function main(){
    var letter = ["i","m","o","u","v","w","x","n"]
    for (var i = 0; i < letter.length; i++) {
        for (var j = 0; j < letter.length; j++) {
            for (var k = 0; k < letter.length; k++) {
                var ret = "";
                ret = ret + letter[i] + letter[j] + letter[k] + letter[j] + letter[i];
                var sha3Hash = web3.utils.sha3(ret)
                await axios.post(
                    'https://api.thegraph.com/subgraphs/name/ensdomains/ens',
                    {
                        operationName: "getRegistrantFromSubgraph",
	                    query: "query getRegistrantFromSubgraph($id: ID!) {\n  registration(id: $id) {\n    id\n    domain {\n      name\n      __typename\n      id\n    }\n    registrant {\n      id\n      __typename\n    }\n    __typename\n  }\n}\n",
                        variables: {
                            id: sha3Hash
                        }
                    }
                ).then(response => {
                    if(response.data.data.registration == null){
                        var context = ret + os.EOL
                        fs.appendFileSync('./files/ens.txt', context)
                        console.log('写入:'+ret)
                    }
                })
            }
        }
    }
}

main()